<template>
  <div>
<!--    <h1>评论管理</h1>-->
    <template>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            label="日期"
            width="220">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.created }}</span>
          </template>
        </el-table-column>
        <el-table-column
            label="发表人"
            width="180">
          <template slot-scope="scope">
            <i class="el-icon-user"></i>
            <span style="margin-left: 10px">{{ scope.row.author }}</span>
          </template>
        </el-table-column>
        <el-table-column
            label="留言/评论"
            width="180">
          <template slot-scope="scope">
            <i class="el-icon-chat-round"></i>
            <span style="margin-left: 10px" v-if="!scope.row.bid">留言</span>
            <span style="margin-left: 10px" v-if="scope.row.bid">评论</span>
          </template>
        </el-table-column>
        <el-table-column
            label="内容">
          <!--            width="180">-->
          <template slot-scope="scope">
            <i class="el-icon-chat-dot-square"></i>
            <span style="margin-left: 10px">{{ scope.row.content }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="right">
          <template slot-scope="scope">
            <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.row.cid)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination class="mpage"
                   background
                   layout="prev, pager, next"
                   :current-page="currentPage"
                   :page-size="pageSize"
                   :total="total"
                   @current-change=page>
    </el-pagination>

  </div>
</template>

<script>
export default {
  name: "commentManage",
  data() {
    return {
      tableData: [],
      currentPage: 1,
      total: 0,
      pageSize: 10
    }
  },
  methods: {
    handleDelete(cid) {
      this.$axios.post("/delCommentByCid/"+cid).then(res=>{

        this.$message({
          type: 'success',
          message: '删除成功'
        })

      })
    },
    page(currentPage) {
      const _this = this
      _this.$axios.post("/listComments?currentPage=" + currentPage).then(res => {
        // console.log('结果测试' + res)
        //这里json数据 不是直接的res.data.data 因为还包括了分页数等等
        _this.tableData = res.data.data.records
        _this.currentPage = res.data.data.current
        _this.total = res.data.data.total
        _this.pageSize = res.data.data.size

      })
    },
  },

  created() {
    this.page(1);
  }
}
</script>

<style scoped>
.mpage {
  margin: 0 auto;
  text-align: center;
}
</style>